

package jumavidesktop.Auxiliar.GUI;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author vimso
 */
public class SoloNumeros extends  PlainDocument{
    
    public void insertString(int arg0, String arg1, AttributeSet arg2) throws BadLocationException
   {
       boolean myError=false;
       for (int i=0;i<arg1.length();i++){
          // si no es digit, volvemos<
          if (!Character.isDigit(arg1.charAt(i) )&& (arg1.charAt(i)!='-'))
             myError=true;
       }
       // Si todos son digit, insertamos el texto en el JTextField
       if (!myError) {
            super.insertString(arg0, arg1, arg2);    
       }
       
   }

}
